package com.qf.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.qf.annotation.RequiresPermissionsDesc;
import com.qf.pojo.DtsAdmin;
import com.qf.pojo.DtsCategory;
import com.qf.pojo.DtsGoods;
import com.qf.service.DtsBrandService;
import com.qf.service.DtsCategoryService;
import com.qf.service.DtsGoodsService;
import com.qf.util.AdminResponseUtil;
import com.qf.util.ResponseUtil;
import com.qf.vo.CatVo;
import com.qf.vo.GoodsAllinone;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.apache.shiro.subject.Subject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author YDW
 * projectName:shop-manage
 * time:2022/5/21 21:28
 * description:
 */
@RestController
@RequestMapping("/admin/category")
public class AdminCategoryController {

    @Autowired
    DtsCategoryService categoryService;

    @RequiresPermissions("admin:category:list")
    @RequiresPermissionsDesc(menu = { "商场管理", "商品类目" }, button = "查询")
    @GetMapping("/list")
    public Object list(
            @RequestParam(name = "page",required = false,defaultValue = "1") Integer page,
            @RequestParam(name = "limit",required = false,defaultValue = "10") Integer limit,
            String sort,String order, Integer id,String name
    ){

        IPage<DtsCategory> ipage =categoryService.queryPage(page,limit,sort,order,id,name);

        Map<String ,Object> data=new HashMap<>();
        data.put("total",ipage.getTotal());
        data.put("items",ipage.getRecords());
        return ResponseUtil.ok(data);


    }


    @GetMapping("/l1")
    public Object l1(){
        //查询分类列表
        List<CatVo> catVos=categoryService.findCategoryListl1();
        return ResponseUtil.ok(catVos);
    }

    @RequiresPermissions("admin:category:update")
    @RequiresPermissionsDesc(menu = { "商场管理", "商品类目" }, button = "编辑")
    @PostMapping("/update")
    public Object update(@RequestBody DtsCategory category){
       return categoryService.update(category);
    }

    @RequiresPermissions("admin:category:detele")
    @RequiresPermissionsDesc(menu = { "商场管理", "商品类目" }, button = "删除")
    @PostMapping("/delete")
    public Object delete(@RequestBody DtsCategory category){
        return categoryService.delete(category);
    }

    @RequiresPermissions("admin:category:create")
    @RequiresPermissionsDesc(menu = { "商场管理", "商品类目" }, button = "新增")
    @PostMapping("/create")
    public Object create(@RequestBody DtsCategory category){
       return categoryService.insert(category);
    }
}
